//FACEBOOK ASYNC CLIENT

//FacebookAsyncUser methods

#include "facebookasync.h"

#include "xmlParser.h"
#include "md5.h"
#include <fstream>
#include <iostream>

//SENDING NOTIFICATION ROUTINES


bool FacebookAsyncUser::SendNotification(std::list<std::string>& UserIDs, const std::string& NotificationFBML)
{
	assert(m_CurLoginStage == LOGINSTAGE_SUCCEED);
	assert(m_CurInfoStage == INFOSTAGE_SUCCEED);
	assert(m_CurPhotoStage == PHOTOSTAGE_NOTSTARTED || m_CurPhotoStage == PHOTOSTAGE_FAILED || m_CurPhotoStage == PHOTOSTAGE_SUCCEED);

	assert(m_CurPostFeedItemStage != POSTFEEDSTAGE_INPROGRESS); 

	assert(m_CurNotificationStage != NOTIFSTAGE_INPROGRESS);

	assert(m_GenericCallInProgress != true);

	assert(m_HasActiveRequest == false);


	//no we may proceed
	std::list<std::string> Params;
	std::string XmlResult;
	
	//preparing params
	Params.push_back("notification=" + NotificationFBML);
	
	std::string UsersIDsString = "to_ids=";

	std::list<std::string>::iterator Iter;

	for (Iter = UserIDs.begin(); Iter != UserIDs.end(); Iter++)
	{
		UsersIDsString.append((*Iter));
		UsersIDsString.append(",");
	}

	UsersIDsString.resize(UsersIDsString.size() - 1); 
	
	Params.push_back(UsersIDsString); 

	FacebookAsync::Instance().Helper_PrepareAPICall("facebook.notifications.send", Params, this); 

	PushNewRequest();

	m_CurNotificationStage = NOTIFSTAGE_INPROGRESS; 

	return true;
}



void FacebookAsyncUser::OnNotificationDone()
{
	assert(m_CurNotificationStage == NOTIFSTAGE_INPROGRESS);

	PullCompletedRequest();

	if (m_CurRequestResult.size() < 1)
	{
		m_CurNotificationStage = NOTIFSTAGE_FAILED;
	}

	m_CurNotificationStage = NOTIFSTAGE_SUCCEED;
}